<?php
/**
 * Created by PhpStorm.
 * User: yuanjie
 * Date: 2017/3/23
 * Time: 下午3:12
 */
use EasyWeChat\Foundation\Application;
class WechatServerController extends BaseController
{
    private $msg;
    public function routes(){
        $wx = Config::get('wechat.CHEPIN');
        $options = $wx['OPTION'];

        $app = new Application($options);
        $server = $app->server;
        $user = $app->user;

        $message = $server->getMessage();
        $user_info = $user->get($message['FromUserName']);
        $this->msg = $user_info->nickname . ",您好！欢迎关注安惠车品！";

        $server->setMessageHandler(function () {
            return $this->msg;
        });
        $response = $app->server->serve();
        return $response;
    }
}